<?php
/**
*+-----------IMBA后台管理广告管理控制器------------+
*+-------------------------------------------------+
*@author susy.liang <liangling@ilongyuan.com.cn>
*+-------------------------------------------------+
*/
namespace Admin\Controller;

class AdController extends BaseManageController {
	/**
	*控制操作的模型表
	*/
	protected $modelName = 'Ad';	

	/**
	*删除类型的设置 true|直接删除， false|设置数据状态
	*/	
	protected $is_del	= false;

	/**
	*操作index的前置操作
	*---设置数据筛选条件---
	*/
	public function _before_index()
	{
		$map = array();//筛选条件
        $map['status'] = array('egt',0);
        
        $adsId = I('get.adsId', 0, 'intval');
        if($adsId)
        	$map['ads_id'] = $adsId;
        $this->where = $map;
        
        $adsData = $this->getAds(array('id'=>$adsId), 'id,name');
        if(empty($adsData))
        	$this->error('广告位不存在');
        $this->adsName = $adsData[$adsId]['name'];

        $this->adsId = $adsId;

	}

	/**
	*操作add的前置操作
	*------设置新增需要的数据条件 ---
	*/
	public function _before_add(){
		if (!IS_POST){			
			$adsId = I('adsId', 0, 'intval');
			$filter = array('id'=>$adsId);
			$field = 'id,name';
			$adsInfo = $this->getAds($filter, $field);
			$this->adsName = $adsInfo[$adsId]['name'];
		}else{
			$adsId = I('ads_id', 0, 'intval');
			$this->jumpAct = U('Ad/index', array('adsId'=>$adsId,));
		}
	}

	/**
	*获取广告位的信息
	*/
	private function getAds($filter=array(), $field=''){		
		$map = array('status'=>array('egt', 0));
		if($filter)
			$map = array_merge($map, $filter);

		$adsMdl = D('Ads', 'Service');
		return $adsMdl->getList($map, $field, true);
	}

	/**
	*操作edit的前置操作
	*------设置编辑需要的数据条件 ---
	*/
	public function _before_edit(){
		if(!IS_POST){
			$field = 'id,name';
			$this->adsData = $this->getAds(array(), $field);
		}else{
			$adsId = I('ads_id', 0, 'intval');
			$this->jumpAct = U('Ad/index', array('adsId'=>$adsId,));
		}
	}

}